package com.youku.plugins.controlbarV4.view.components
{
   import flash.display.Sprite;
   import flash.display.DisplayObject;
   import flash.text.TextField;
   import com.youku.baseUI.BasePlayerButton;
   import flash.utils.Timer;
   import com.youku.utils.AssetUtil;
   import com.youku.plugins.controlbarV4.ControlBarFont;
   import com.youku.utils.DrawUtil;
   import flash.events.MouseEvent;
   import flash.events.TimerEvent;
   import com.youku.plugins.controlbarV4.ControlBarConstant;
   import com.youku.plugins.controlbarV4.view.events.InformationBarEvent;
   import com.youku.utils.ReportUtil;
   import com.youku.PlayerConfig;
   
   public class InformationBar extends Sprite
   {
      
      public function InformationBar() {
         super();
         this.init();
      }
      
      public static const INFORMATION_BAR_HEIGHT:Number = 30;
      
      public static const CLOSE_VERY_LONG_TIMEOUT:Number = 20 * 1000;
      
      public static const CLOSE_LONG_TIMEOUT:Number = 10 * 1000;
      
      public static const CLOSE_SHORT_TIMEOUT:Number = 5 * 1000;
      
      public static const CLOSE_NO_TIMEOUT:Number = 100 * 1000 * 1000;
      
      protected var _background:DisplayObject;
      
      protected var _infoText:TextField;
      
      protected var _infoLine:Sprite;
      
      protected var _infoLayer:Sprite;
      
      protected var _closeIcon:BasePlayerButton;
      
      protected var _width:Number;
      
      protected var _height:Number;
      
      protected var _isShowing:Boolean;
      
      protected var _notToShowOther:Boolean = false;
      
      protected var _waitingList:Array;
      
      protected var _currentType:String = "INFOBAR_NONE";
      
      protected var _closeTimer:Timer;
      
      protected var _span:Number = 16;
      
      private function init() : void {
         this._background = AssetUtil.getAsset("V4_panel_bg");
         this._infoText = new TextField();
         this._infoText.defaultTextFormat = ControlBarFont.FONT_INFORBAR_INFO;
         this._infoText.selectable = false;
         this._infoText.width = 500;
         this._infoText.height = 25;
         this._infoLine = DrawUtil.RectangleSprite(0,0,100,1,3845631,1,null,0);
         this._infoLayer = DrawUtil.RectangleSprite(0,0,100,18,3845631,0,null,0);
         this._infoLayer.buttonMode = true;
         this._infoLayer.useHandCursor = true;
         this._closeIcon = AssetUtil.getStyleButton("P_CloseButton");
         AssetUtil.restoreButtonSize(this._closeIcon);
         addChild(this._background);
         addChild(this._infoText);
         addChild(this._infoLayer);
         addChild(this._closeIcon);
         this._infoLayer.addEventListener(MouseEvent.CLICK,this.onContinuousSetClick);
         this._closeIcon.addEventListener(MouseEvent.CLICK,this.onCloseClick);
         this._closeTimer = new Timer(CLOSE_LONG_TIMEOUT);
         this._closeTimer.addEventListener(TimerEvent.TIMER,this.onCloseTimeout);
         this._infoLine.x = 0;
         this._infoLine.y = 22;
         this._infoLayer.x = 0;
         this._infoLayer.y = 4;
         this.setSize(500,20);
         this._waitingList = new Array();
         this._isShowing = false;
         this.changeType(ControlBarConstant.INFOBAR_NONE);
      }
      
      private function onContinuousSetClick(param1:MouseEvent) : void {
         var _loc2_:String = InformationBarEvent.SETTING_CLICK;
         switch(this._currentType)
         {
            case ControlBarConstant.INFOBAR_HIGH_QUALITY_HINT:
               ReportUtil.sendUserActionLog(ReportUtil.SUPER_HIGH_DEFINITION_SWITCH_HINT);
               _loc2_ = InformationBarEvent.QUALITY_CLICK;
               break;
            case ControlBarConstant.INFOBAR_RESTORE_LAST:
               _loc2_ = InformationBarEvent.SEEK_TO_BEGIN_CLICK;
               break;
            case ControlBarConstant.INFOBAR_JUMP_HEAD_SETTING:
            case ControlBarConstant.INFOBAR_JUMP_HEAD:
            case ControlBarConstant.INFOBAR_JUMP_TAIL:
            case ControlBarConstant.INFOBAR_JUMP_TAIL_SETTING:
               ReportUtil.sendUserActionLog(ReportUtil.SKIP_HEADTAIL_SETTINGS_HINT);
               break;
            case ControlBarConstant.INFOBAR_CONTINUOUS_SETTING:
               ReportUtil.sendUserActionLog(ReportUtil.CHAIN_PLAY_HINT);
               break;
            case ControlBarConstant.INFOBAR_RESTORE_LAST:
            case ControlBarConstant.INFOBAR_RESTORE_SERVER:
               _loc2_ = InformationBarEvent.SEEK_TO_BEGIN_CLICK;
               break;
            case ControlBarConstant.INFOBAR_TEMP_SWITCH_TO_LOW:
               _loc2_ = InformationBarEvent.SWITCH_TO_LOW_CLICK;
               break;
            case ControlBarConstant.INFOBAR_INSTALL_IKU:
               _loc2_ = InformationBarEvent.INSTALL_IKU_CLICK;
               break;
            case ControlBarConstant.INFOBAR_TRIAL:
               _loc2_ = InformationBarEvent.BUY_CLICK;
               break;
            case ControlBarConstant.INFOBAR_OPEN_WINDOW_HINT:
               _loc2_ = InformationBarEvent.COPY_LINK_CLICK;
               break;
            case ControlBarConstant.INFOBAR_AD_SHARE:
               _loc2_ = InformationBarEvent.AD_SHARE_CLICK;
               break;
            case ControlBarConstant.INFOBAR_INTERNET_SLOW:
               _loc2_ = InformationBarEvent.INTERNET_SLOW_CLICK;
               break;
            case ControlBarConstant.INFOBAR_ACCELERATE:
               _loc2_ = InformationBarEvent.INTERNET_ACCELERATE_CLICK;
               break;
         }
         dispatchEvent(new InformationBarEvent(_loc2_));
      }
      
      private function onCloseClick(param1:MouseEvent) : void {
         this.tryToShowNext();
      }
      
      public function setSize(param1:Number, param2:Number) : void {
         this._width = param1;
         this._height = INFORMATION_BAR_HEIGHT;
         this._background.width = this._width;
         this._background.height = this._height;
         this.updateLayout();
      }
      
      protected function updateLayout() : void {
         this._background.x = 0;
         this._background.y = 0;
         this._infoText.x = 5;
         this._infoText.y = 0;
         this._closeIcon.x = this._background.x + this._background.width - this._closeIcon.width - 10;
         this._closeIcon.y = 5;
      }
      
      public function changeType(param1:String, param2:Object = null) : void {
         var _loc3_:String = null;
         if(this._notToShowOther)
         {
            return;
         }
         this._closeTimer.delay = CLOSE_LONG_TIMEOUT;
         this._infoLine.visible = false;
         this._infoLine.width = 30;
         this._infoLayer.visible = false;
         this._infoLayer.width = 30;
         this._closeIcon.visible = true;
         this._currentType = param1;
         switch(param1)
         {
            case ControlBarConstant.INFOBAR_CONTINUOUS_PLAY:
               this._infoText.htmlText = ControlBarConstant.TEXT_CONTINUOUS_PLAY;
               this._infoLayer.visible = true;
               this._infoLayer.x = 276 - this._span;
               break;
            case ControlBarConstant.INFOBAR_CONTINUOUS_SETTING:
               this._infoText.htmlText = ControlBarConstant.TEXT_CONTINUOUS_SETTING;
               this._infoLayer.visible = true;
               this._infoLayer.x = 155 - this._span;
               this._infoLayer.width = 58;
               break;
            case ControlBarConstant.INFOBAR_JUMP_HEAD:
               this._infoText.htmlText = ControlBarConstant.TEXT_JUMP_HEAD;
               this._infoLayer.visible = true;
               this._infoLayer.x = 150 - this._span;
               break;
            case ControlBarConstant.INFOBAR_JUMP_HEAD_SETTING:
               this._infoText.htmlText = ControlBarConstant.TEXT_JUMP_HEAD_SETTING;
               this._infoLayer.visible = true;
               this._infoLayer.x = 222 - this._span;
               break;
            case ControlBarConstant.INFOBAR_JUMP_TAIL:
               this._infoText.htmlText = ControlBarConstant.TEXT_JUMP_TAIL;
               this._infoLayer.visible = true;
               this._infoLayer.x = 150 - this._span;
               this._closeTimer.delay = CLOSE_VERY_LONG_TIMEOUT;
               break;
            case ControlBarConstant.INFOBAR_JUMP_TAIL_SETTING:
               this._infoText.htmlText = ControlBarConstant.TEXT_JUMP_TAIL_SETTING;
               this._infoLayer.visible = true;
               this._infoLayer.x = 222 - this._span;
               this._closeTimer.delay = CLOSE_VERY_LONG_TIMEOUT;
               break;
            case ControlBarConstant.INFOBAR_RESTORE_LAST:
               this._infoText.htmlText = ControlBarConstant.TEXT_RESTORE_LAST.replace("{data}",param2.time);
               this._infoLayer.visible = true;
               this._infoLayer.x = 214 - this._span;
               this._infoLayer.width = 58;
               this._closeTimer.delay = CLOSE_LONG_TIMEOUT;
               break;
            case ControlBarConstant.INFOBAR_RESTORE_SERVER:
               this._infoText.htmlText = ControlBarConstant.TEXT_RESTORE_SERVER.replace("{data}",param2.time);
               this._infoLayer.visible = true;
               this._infoLayer.x = 228 - this._span;
               this._infoLayer.width = 58;
               this._closeTimer.delay = CLOSE_LONG_TIMEOUT;
               break;
            case ControlBarConstant.INFOBAR_ENTER_INSERT_AD:
               this._infoText.htmlText = ControlBarConstant.TEXT_ENTER_INSERT_AD;
               this._closeTimer.delay = CLOSE_LONG_TIMEOUT;
               break;
            case ControlBarConstant.INFOBAR_HIGH_QUALITY_HINT:
               this._infoText.htmlText = ControlBarConstant.TEXT_HIGH_QUALITY_HINT;
               this._infoLayer.visible = true;
               this._infoLayer.x = 278 - this._span;
               break;
            case ControlBarConstant.INFOBAR_TEMP_SWITCH_TO_LOW:
               this._infoText.htmlText = ControlBarConstant.TEXT_TEMP_SWITCH_TO_LOW;
               this._infoLayer.visible = true;
               this._infoLayer.x = 320 - this._span;
               this._closeTimer.delay = CLOSE_VERY_LONG_TIMEOUT;
               if(PlayerConfig.accState == 0 && Math.random() > 0.5)
               {
                  this._infoText.htmlText = ControlBarConstant.TEXT_ACCELERATE_REGISTER;
                  this._infoLayer.visible = true;
                  this._infoLayer.width = 60;
                  this._infoLayer.x = 288 - this._span;
                  this._closeTimer.delay = CLOSE_LONG_TIMEOUT;
                  this._currentType = ControlBarConstant.INFOBAR_ACCELERATE;
               }
               break;
            case ControlBarConstant.INFOBAR_ACCELERATE:
               this._infoText.htmlText = ControlBarConstant.TEXT_ACCELERATE_LOGINED;
               this._closeTimer.delay = CLOSE_SHORT_TIMEOUT;
               break;
            case ControlBarConstant.INFOBAR_INSTALL_IKU:
               this._infoText.htmlText = ControlBarConstant.TEXT_INSTALL_IKU;
               this._infoLayer.visible = true;
               this._infoLayer.x = 290 - this._span;
               this._infoLayer.width = 70;
               break;
            case ControlBarConstant.INFOBAR_TRIAL:
               _loc3_ = "体验视频";
               if((param2) && (param2.text))
               {
                  _loc3_ = param2.text;
               }
               this._infoText.htmlText = ControlBarConstant.TEXT_TRIAL.replace("{data}",_loc3_);
               this._notToShowOther = true;
               this._closeIcon.visible = true;
               this._closeTimer.delay = CLOSE_NO_TIMEOUT;
               this._infoLayer.visible = true;
               this._infoLayer.x = 302 - this._span;
               this._infoLayer.width = 78;
               break;
            case ControlBarConstant.INFOBAR_PAUSE_IKU:
               this._infoText.htmlText = ControlBarConstant.TEXT_PAUSE_IKU;
               break;
            case ControlBarConstant.INFOBAR_OPEN_WINDOW_HINT:
               this._infoText.htmlText = ControlBarConstant.TEXT_OPEN_WINDOW_HINT;
               this._infoLayer.visible = true;
               this._infoLayer.x = 248 - this._span;
               this._infoLayer.width = 87;
               break;
            case ControlBarConstant.INFOBAR_OPEN_WINDOW_COPYIED:
               this._infoText.htmlText = ControlBarConstant.TEXT_OPEN_WINDOW_COPYIED;
               this._closeTimer.delay = CLOSE_SHORT_TIMEOUT;
               break;
            case ControlBarConstant.INFOBAR_AD_SHARE:
               this._infoText.htmlText = ControlBarConstant.TEXT_AD_SHARE;
               this._infoLayer.visible = true;
               this._infoLayer.x = 267 - this._span;
               this._infoLayer.width = 57;
               break;
            case ControlBarConstant.INFOBAR_AD_SKIP:
               this._infoText.htmlText = ControlBarConstant.TEXT_AD_SKIP;
               this._infoLayer.visible = true;
               this._infoLayer.x = 267 - this._span;
               this._infoLayer.width = 57;
               break;
            case ControlBarConstant.INFOBAR_VIP_SHARE:
               this._infoText.htmlText = PlayerConfig.playListData.user.vipnotes;
               break;
            case ControlBarConstant.INFOBAR_INTERNET_SLOW:
               this._infoText.htmlText = ControlBarConstant.TEXT_INTERNET_SLOW;
               this._infoLayer.visible = true;
               this._infoLayer.x = 148 - this._span;
               this._infoLayer.width = 30;
               break;
            case ControlBarConstant.INFOBAR_NONE:
               break;
         }
      }
      
      public function appendTypeToShow(param1:String) : void {
         if(this._isShowing)
         {
            this._waitingList.push(param1);
         }
         else
         {
            this.changeType(param1);
         }
      }
      
      public function show() : void {
         this.visible = true;
         this._closeTimer.reset();
         this._closeTimer.start();
         this._isShowing = true;
         this.dispatchEvent(new InformationBarEvent(InformationBarEvent.BAR_SHOW));
      }
      
      public function hide() : void {
         this._closeTimer.stop();
         this._waitingList = [];
         this.visible = false;
         this._isShowing = false;
         this.dispatchEvent(new InformationBarEvent(InformationBarEvent.BAR_HIDE));
      }
      
      private function onCloseTimeout(param1:TimerEvent) : void {
         this._closeTimer.stop();
         this.tryToShowNext();
      }
      
      private function tryToShowNext() : void {
         var _loc1_:String = null;
         if(this._waitingList.length > 0)
         {
            _loc1_ = this._waitingList.shift();
            this.changeType(_loc1_);
            this.show();
         }
         else
         {
            this.hide();
         }
      }
      
      override public function get width() : Number {
         return this._background.width;
      }
      
      override public function get height() : Number {
         return this._background.height;
      }
   }
}
